package com.wanxi.stream;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class MapStream {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("zhangsan,23");
        list.add("lisi,24");
        list.add("wangwu,25");
        Map<String, String> collect = list.stream().filter(s ->
                Integer.parseInt(s.split(",")[1]) >= 24
        ).collect(Collectors.toMap(s -> s.split(",")[0], s -> s.split(",")[1]));
//        Map<Object, Object> collect = list.stream().filter(new Predicate<String>() {
//            @Override
//            public boolean test(String s) {
//                String ageStr = s.split(",")[1];
//                Integer age = Integer.valueOf(ageStr);
//                return age >= 24;
//            }
//        }).collect(Collectors.toMap(new Function<String, Object>() {
//            @Override
//            public Object apply(String s) {
//                System.out.println(s + "+++++++");
//                return s.split(",")[0];
//            }
//        }, new Function<String, Object>() {
//            @Override
//            public Object apply(String s) {
//                System.out.println(s + "------");
//                return s.split(",")[1];
//            }
//        }));

        System.out.println(collect);
    }
}
